package com.neusoft.neuiotms.dcom.repository.problem.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.problem.ProblemRegistration;
import com.neusoft.neuiotms.dcom.model.problem.QProblemRegistration;
import com.neusoft.neuiotms.dcom.repository.problem.CustomizedProblemRegistrationRepository;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedProblemRegistrationRepositoryImpl extends AbstractRepository
        implements CustomizedProblemRegistrationRepository {

    @Override
    protected Class<?> getModelClass() {
        return ProblemRegistration.class;
    }

    @Override
    public ProblemRegistration findByWorkNum(final String workOrderNum) {
        final QProblemRegistration qProblemRegistration = QProblemRegistration.problemRegistration;
        final JPAQuery<ProblemRegistration> query = this.query().selectFrom(qProblemRegistration);
        query.where(qProblemRegistration.workOrderNum.eq(workOrderNum))
                .orderBy(qProblemRegistration.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
